// var objPie = $("#main");
// $(document).ready(function () {
//     changeWin(objPie,200);
//     $(".stateSearchPopup").find(".close").click(function () {
//         $(".stateSearchPopup").css("display", "none");
//     })
//     // datepicker基本设置
//     $.datepicker.parseDate("yy/mm/dd", "2007/01/26");
//     $('#startTime').datetimepicker({
//         defaultDate: $('#startTime').val(),
//         timeFormat: "HH:mm:ss",
//         dateFormat: "yy-mm-dd",
//         changeMonth: true,
//         onClose: function (selectedDate) {
//             $("#endTime").datepicker("option", "minDate", selectedDate);
//         }
//     });
//     $('#endTime').datetimepicker({
//         defaultDate: $('#endTime').val(),
//         timeFormat: "HH:mm:ss",
//         dateFormat: "yy-mm-dd",
//         changeMonth: true,
//         onClose: function (selectedDate) {
//             $("#startTime").datepicker("option", "maxDate", selectedDate);
//         }
//     });
//     loadPie();
//
// })
function loadPie() {
    $.ajax({
        type:"post",
        url:"/sysmanage/devicedata/statistics.do",
        data:"",
        dataType:"json",
        success:function (data) {
            if(data!=null){
                pieChange(data.deviceNormal,data.deviceAbnormal);
            }
        }
    })
}
function stateSaveTime(piefresh) {
    var startTime ;
    var endTime;
    if(piefresh=1){
        startTime="";
        endTime="";
    }else{
        startTime = $("#startTime").val();
        endTime = $("#endTime").val();
    }
        $.ajax({
            type: "post",
            url: "/sysmanage/devicedata/statistics.do",
            data: {"startTime": startTime, "endTime": endTime},
            dataType: "json",
            success: function (data) {
                if(data!=null){
                    pieChange(data.deviceNormal,data.deviceAbnormal);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(textStatus);
            }
        })

}
function pieChange(normalNum,abnormalNum) {
    var myPie = echarts.init(document.getElementById('main'));
    myPie.setOption(option = {
        title : {
            text: '设备上报状态统计',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{b} :{d}%"
        },
        legend: {
            bottom: 10,
            left: 'center',
            data: ['设备数据正常','设备数据异常']
        },
        toolbox: {
            show : true,
            x:$("#navtabbox").width()-92+'px',
            feature : {
                mark : {show: true},
                myTool1: {
                    show: true,
                    title: '还原',
                    icon:'path://M13.353,19.993v2.001C19.265,21.808,24,16.957,24,11c0-6.075-4.925-11-11-11C7.434,0,2.833,4.135,2.101,9.5H0L3,13l3-3.5H4.124C4.839,5.243,8.54,2,13,2c4.971,0,9,4.029,9,9C22,15.852,18.16,19.808,13.353,19.993z' ,
                    onclick: function () {
                        var piefresh=1;
                        stateSaveTime(piefresh);
                    }
                },
                myTool2: {
                    show: true,
                    title: '设置时间',
                    icon: 'path://M470.056,294.698c-34.065-40.043-76.799-64.447-128.196-73.213v-36.457h2.988c5.978,0,10.957-1.992,14.94-5.977\n' +
                    '\tc3.983-3.985,5.978-8.965,5.978-14.941s-1.992-10.957-5.978-14.941c-3.986-3.984-8.965-5.977-14.94-5.977h-77.696v-0.001\n' +
                    '\tc-5.977,0-10.957,1.992-14.941,5.977s-5.977,8.965-5.977,14.941s1.992,10.957,5.977,14.941c3.985,3.984,8.965,5.977,14.941,5.977\n' +
                    '\th2.988v36.457c-51.398,8.766-94.131,33.17-128.197,73.213c-34.066,40.043-51.1,86.361-51.1,138.957\n' +
                    '\tc0,39.047,9.562,75.104,28.688,108.176c19.126,33.07,45.223,59.168,78.293,78.293c33.07,19.125,69.129,28.688,108.176,28.688\n' +
                    '\ts75.105-9.562,108.176-28.688c33.071-19.126,59.168-45.224,78.293-78.293c19.125-33.07,28.688-69.129,28.688-108.176\n' +
                    '\tC521.157,381.059,504.124,334.741,470.056,294.698z M427.025,554.975c-33.27,33.47-73.611,50.205-121.025,50.205\n' +
                    '\ts-87.756-16.732-121.025-50.203c-33.269-33.469-49.904-73.811-49.904-121.023c0-47.214,16.635-87.557,49.904-121.025\n' +
                    '\tS258.586,262.723,306,262.723s87.756,16.734,121.025,50.203c33.269,33.469,49.902,73.812,49.902,121.025\n' +
                    '\tS460.293,521.508,427.025,554.975z M370.547,361.336l34.664-4.184l-8.965,33.469l-78.293,67.535H306h-4.781h-2.391\n' +
                    '\tc-3.586,0-6.574-1.196-8.965-3.586c-2.391-2.391-3.586-5.18-3.586-8.367v-2.391v-4.781V311.133L306,282.445l19.723,28.688v89.648\n' +
                    '\tL370.547,361.336z',
                    onclick: function () {

                        $(".stateSearchPopup").slideToggle("slow");
                    }
                }
            }
        },
        series : [
            {
                name: '访问来源',
                type: 'pie',
                radius : '55%',
                center: ['50%', '50%'],
                data:[
                    {
                        value:abnormalNum,
                        name:'设备数据异常',
                        itemStyle:{
                            normal:{
                                color:'rgb(84,101,112)'

                            }
                        }
                    },
                    {
                        value:normalNum,
                        name:'设备数据正常',
                        itemStyle:{
                            normal:{
                                color:'rgb(145,199,174)'
                            }
                        }
                    }
                ],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    }
);
    window.onresize = myPie.resize;
}
